import localforage from 'localforage'
import bookContract from '../contracts/db/bookshelfContract'
import bookContentContract from '../contracts/db/bookContentContract'

/**
 * 获取书架数据库
 * @param {*} storeName
 * @returns
 */
export function getBookshelfDb(storeName) {
  return localforage.createInstance({
    name: bookContract.db,
    driver: localforage.INDEXEDDB,
    storeName: storeName,
  })
}

/**
 * 获取书籍内容数据库
 * @param {*} dbName 数据库名称
 * @param {*} storeName 表名称
 * @returns
 */
export function getBookContentDb(dbName, storeName) {
  return localforage.createInstance({
    name: `${bookContentContract.dbSuffix}-${dbName}`,
    driver: localforage.INDEXEDDB,
    storeName: `${bookContentContract.storeSuffix}-${storeName}`,
  })
}
